<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Screen Shader</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Import maps polyfill -->
    <!-- Remove this when import maps will be widely supported -->
    <script async src="https://unpkg.com/es-module-shims@1.6.3/dist/es-module-shims.js"></script>

    <script type="importmap">
    {
        "imports": {
          "threepipe": "./../../dist/index.mjs"
        }
    }

    </script>
    <style id="example-style">
        html, body, #canvas-container, #mcanvas {
            width: 100%;
            height: 100%;
            margin: 0;
            overflow: hidden;
        }
    </style>
    <script type="module" src="../examples-utils/global-loading.mjs"></script>
    <script type="module" src="../examples-utils/simple-code-preview.mjs"></script>
    <script id="example-script" type="module">
        import {_testFinish, _testStart, ThreeViewer} from 'threepipe'

        // Set a custom screen shader snippet to modify the final rendered image.
        // Here, `diffuseColor` is the final color of the pixel which can be modified.
        // This happens before the final post-processing effects(like tonemap, vignette, film-grain etc.) are applied.
        // Checkout the ScreenPass guide for more details: https://threepipe.org/docs/guides/screen-pass
        const viewer = new ThreeViewer({
            canvas: document.getElementById('mcanvas'),
            screenShader: `
            // add a basic red tint
            diffuseColor *= vec4(1.0, 0.0, 0.0, 1.0);
            `
        })

        async function init() {
            viewer.scene.backgroundColor.set(0)

            await Promise.all([
                viewer.setEnvironmentMap('https://samples.threepipe.org/minimal/venice_sunset_1k.hdr'),
                viewer.load('https://samples.threepipe.org/minimal/DamagedHelmet/glTF/DamagedHelmet.gltf', {
                    autoCenter: true,
                    autoScale: true,
                })])
        }

        _testStart()
        init().finally(_testFinish)
    </script>
</head>
<body>
<div id="canvas-container">
    <canvas id="mcanvas"></canvas>
</div>

</body>
